from django.db import models
from users.models import User


class Restaurant(models.Model):
    name = models.CharField(max_length=100, verbose_name='餐厅名称')
    owner = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='店主')
    address = models.CharField(max_length=200, verbose_name='餐厅地址')
    phone = models.CharField(max_length=11, verbose_name='联系电话')
    description = models.TextField(verbose_name='餐厅描述', blank=True)
    image = models.ImageField(upload_to='restaurant_images/', verbose_name='餐厅图片', blank=True)
    rating = models.FloatField(default=5.0, verbose_name='评分')
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')

    class Meta:
        verbose_name = '餐厅'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


from django.db import models


class Merchant(models.Model):
    name = models.CharField(max_length=100, verbose_name="商家名称")
    address = models.CharField(max_length=200, verbose_name="地址")
    phone = models.CharField(max_length=20, verbose_name="联系电话")
    description = models.TextField(verbose_name="商家描述", blank=True)

    class Meta:
        verbose_name = "商家"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class MenuItem(models.Model):
    merchant = models.ForeignKey(Merchant, on_delete=models.CASCADE, verbose_name="所属商家")
    name = models.CharField(max_length=100, verbose_name="菜品名称")
    price = models.DecimalField(max_digits=6, decimal_places=2, verbose_name="价格")
    description = models.TextField(verbose_name="描述", blank=True)


class Dish(models.Model):
    restaurant = models.ForeignKey(Restaurant, on_delete=models.CASCADE, verbose_name='所属餐厅')
    name = models.CharField(max_length=100, verbose_name='菜品名称')
    price = models.DecimalField(max_digits=8, decimal_places=2, verbose_name='价格')
    description = models.TextField(verbose_name='菜品描述', blank=True)
    image = models.ImageField(upload_to='dish_images/', verbose_name='菜品图片', blank=True)
    is_available = models.BooleanField(default=True, verbose_name='是否可用')

    class Meta:
        verbose_name = '菜品'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name
